"use strict";
const { Model, Sequelize } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Receipt extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      Receipt.belongsTo(models.Client, {
        foreignKey: "client_id",
        allowNull: true,
      });
      Receipt.belongsTo(models.Contract, {
        foreignKey: "contract_id",
        onDelete: "CASCADE",
      });
      Receipt.belongsTo(models.Project, {
        foreignKey: "project_id",
        allowNull: true,
      });
      // define association here
    }
  }
  Receipt.init(
    {
      signed_time: {
        type: DataTypes.DATE,
        defaultValue: Sequelize.NOW,
      },
      periods: DataTypes.INTEGER,
      period_money: DataTypes.DOUBLE,
      invoiced: DataTypes.BOOLEAN,
      expected_invoice_time: DataTypes.DATE,
      invoiced_time: {
        type: DataTypes.DATE,
        defaultValue: Sequelize.NOW,
      },
      invoiced_money: DataTypes.DOUBLE,
      expected_receive_time: DataTypes.DATE,
      received_time: DataTypes.DATE,
      received: DataTypes.BOOLEAN,
      remarks: DataTypes.STRING,
    },
    {
      sequelize,
      modelName: "Receipt",
      tableName: "receipts",
    }
  );
  return Receipt;
};
